<template>
  <div>
    <div style="margin-left: 1rem;margin-top: 1rem;">
      学科：
      <el-select v-model="label" placeholder="请选择" style="width: 240px">
        <el-option v-for="item in arr" :key="item.id" :label="item.name" :value="item.id">
          <span style="float: left">{{ item.name }}</span>
          <span style="
          float: right;
          color: var(--el-text-color-secondary);
          font-size: 13px;
        ">{{ item.levelName }}
          </span>
        </el-option>
      </el-select>
      <el-button type="primary" style="margin-left: 1rem;" @click="onSubmit">查询</el-button>
    </div>
    <div style="width: 98%; margin-left: 1rem; margin-top: 2rem;">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="Id" width="90" />
        <el-table-column prop="paperName" label="试卷名称" width="300" />
        <el-table-column prop="userName" label="用户名称" width="300" />
        <el-table-column label="得分" width="90">
          <template #default="scope">
            <span>{{ scope.row.userScore }}/ {{ scope.row.paperScore }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="questionCorrect" label="题目对错" width="90">
          <template #default="scope">
            <span>{{ scope.row.questionCorrect }}/ {{ scope.row.questionCount }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="doTime" label="耗时" width="90" />
        <el-table-column prop="createTime" label="提交时间" />
      </el-table>
    </div>
    <div style="margin-left: 1rem ;margin-top: 3rem;">
      <el-pagination v-model:current-page="biaodan.pageIndex" v-model:page-size="biaodan.pageSize"
        :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { subjectPage, type SubjectdaType } from '@/api/dajuan'
import { subjectPage1, type SubjectdaType1 } from '@/api/xueke'
// 表单数据
const biaodan = ref({
  Id:null,
  paperName:"",
  subjectId: null,
  pageIndex: 1,
  pageSize: 10
})

// 搜索
const biaodan1 = ref({
    sendUserName: null
})
const arr=ref<any>([])
let label=ref(
  arr.value.id
)
function getList1() {
  subjectPage1(biaodan1.value).then(res => {
    console.log(res,"2");
   arr.value= res.response
  })
}
getList1()
const onSubmit = ()=>{
getList()
}
//表格
const tableData = ref<SubjectdaType[]>([])
function getList() {
  subjectPage(biaodan.value).then(res => {
    console.log(res, "subject");
    if (res.code === 1) {
      tableData.value = (res.response?.list as SubjectdaType[])
      total.value = (res.response?.total as number)
    }
  })
}
getList()
//页码
// 总页数
const total = ref(0)
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
  biaodan.value.pageSize = val;
  getList()
}
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
  biaodan.value.pageIndex = val;
  getList()
}
</script>
